package com.sntk.organauthomanager.infrastructure.session;

import com.sntk.organauthomanager.application.dto.OperatorInfo;
import com.sntk.organauthomanager.infrastructure.exception.LoginInfoNotFoundException;

import javax.servlet.http.HttpSession;

/**
 * @ClassName: LoginSessionInfo
 * @author: wgchao
 * @createTime: 2020/7/20 5:13 PM
 * @Description: TODO
 */
public class LoginSessionInfo {
    private String env = "pro";
    private HttpSession session;

    private LoginSessionInfo(HttpSession session) {
        this.session = session;
    }

    public static LoginSessionInfo generate(HttpSession session){
        return new LoginSessionInfo(session);
    }

    public OperatorInfo getOperatorInfo(){
        if(this.env.equals("dev")){
            return new OperatorInfo("admin", "admin", "3702", "系统", 0);
        }
        OperatorInfo operatorInfo = (OperatorInfo) this.session.getAttribute("loginUser");
        if(operatorInfo == null){
            throw new LoginInfoNotFoundException();
        }
        return operatorInfo;
    }

    public String getOperator(){
        if(this.env.equals("dev")){
            return "admin";
        }
        return getOperatorInfo().getOperator();
    }
}
